#! /bin/bash


function rand_get_picture(){
    # echo "[INFO] --- rand_get_picture ---"
    file_path=$1;
    # 得到结果数量
    # ls | wc -l  计算结果数量
    res1=`ls $file_path | grep -E ".png|.jpeg|.jpg" | wc -l`
    # echo $res1;
    # 产生1－结果数之间的一个随机数
    res2=$[RANDOM%$res1];
    # echo $res2;
    res3=`ls $file_path | grep -E ".png|.jpeg|.jpg" | awk NR=="$res2" `
    # echo $res3;

    echo $file_path"/"$res3;

    # [Shell脚本(三剑客 sed、awk、grep 案例)_Jerry00713的博客-CSDN博客](https://blog.csdn.net/Jerry00713/article/details/108197802)
    # [Shell函数返回值_AllardZhao的博客-CSDN博客_shell 函数返回值](https://blog.csdn.net/qq_37189082/article/details/121894595)
    # [使用awk命令获取文本的某一行，某一列_姥爷wvb的博客-CSDN博客_awk取第二行](https://blog.csdn.net/aywb1314/article/details/52239281)
    # [Linux常用命令之RANDOM_nsq1101的博客-CSDN博客_linux random](https://blog.csdn.net/weixin_45063703/article/details/117227856)
}

picture_file_pwd=`rand_get_picture $HOME"/Pictures/wallpapers"`
echo "$picture_file_pwd"
